import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { UserModule } from '../user/user.module';
import { AuthService } from './auth.service';
import { JWTStrategyService } from './jwt.srategy.service';
import { LocalStrategyService } from './local.strategy.service';

@Module({
  imports: [
    PassportModule,
    ConfigModule,
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => {
        return {
          secret: configService.get('API_ACCESS_TOKEN_SECRET'),
          signOptions: {
            expiresIn: `${configService.get(
              'API_ACCESS_TOKEN_TTL_IN_MINUTES',
            )}m`,
            // NOTICE: 这里存在过期时间
          },
        };
      },
      inject: [ConfigService],
    }),
    UserModule,
  ],
  providers: [AuthService, LocalStrategyService, JWTStrategyService],
  exports: [AuthService],
})
export class AuthModule {}
